package com.android.lovely.ui.dialog

import androidx.core.os.bundleOf
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.lifecycleScope
import com.android.lovely.R
import com.android.lovely.databinding.DialogCreateRoleBinding
import com.android.lovely.framework.BaseDialogFragment
import com.android.lovely.ui.viewmodel.CreateRoleViewModel
import com.kotlin.extensions.coroutine.CoroutineExt.launchSafety
import com.kotlin.extensions.view.ViewExt.clickable
import kotlinx.coroutines.flow.collectLatest

/**
 *
 * @author why
 * @date 2025/4/9 01:29
 */
class SmartCreateRoleDialog: BaseDialogFragment<DialogCreateRoleBinding>() {
    val viewModel by activityViewModels<CreateRoleViewModel>()

    override fun initializeViews() {
        lifecycleScope.launchSafety {
            viewModel.quickCostFlow.collectLatest {
                "($it ${getString(R.string.gems)})".also { binding.price.text = it }
            }
        }
        binding.cancel.clickable {
            dismissAllowingStateLoss()
        }
        binding.confirm.clickable {
            dismissAllowingStateLoss()
            viewModel.quickGenerate()
            GenerateRoleDialog().show(requireActivity().supportFragmentManager)
        }
    }
}